<template>
<view class="container">
  <view class="order-info">
      <view class="t">
        <text class="lable">订单编号：</text>
        <text class="value">{{orderInfo.orderSn}}</text>
      </view>
      <view class="t">
        <text class="lable">下单时间：</text>
        <text class="value">{{orderInfo.addTime}}</text>
      </view>
      <view class="t">
        <text class="lable">联系人：</text>
        <text class="value">{{orderInfo.consignee}} {{orderInfo.mobile}}</text>
      </view>
      <view class="about-item">
        <view class="item-left">
          <label class="jhx_f12">地址: </label>
          <text>{{brand.address}}</text> 
        </view>
        <view class="item-right" @tap="showLocation" v-if="brand.longitude != 0 && brand.latitude != 0">
          <image src="/static/static/images/ico-addr.png" class="right-icon"></image>
        </view>
      </view>
      <view class="about-item">
        <view class="item-left">
          <label class="jhx_f12">取货时间: </label>
          <text>{{brand.fetchTimeRules}}</text> 
        </view>
      </view>
  </view>
  

  <view class="order-goods">
    <view class="h">
      <view class="label">商品信息</view>
      <view class="status">{{orderInfo.orderStatusText}}</view>
    </view>
    <view class="goods">
      <view v-for="(item, index) in orderGoods" :key="index" class="item">
        <view class="img">
          <image :src="item.picUrl"></image>
        </view>
        <view class="info">
          <view class="t">
            <text class="name">{{item.goodsName}}</text>
          </view>
          <view class="t">
            <text class="attr">规格：{{item.specifications.toString()}}</text>
            <text class="number">x{{item.number}}</text>
          </view>
          <view class="price">￥{{item.price}}</view>
          <view class="btn active" v-if="handleOption.comment && (item.comment == 0)">
            <navigator :url="'../../commentPost/commentPost?orderId=' + item.orderId + '&&valueId=' + item.goodsId + '&type=0'">去评价</navigator>
          </view>
          <view class="btn active" v-if="handleOption.rebuy">
            <navigator :url="'../../goods/goods?id=' + item.goodsId">再次购买</navigator>
          </view>
        </view>
      </view>
    </view>

    <view class="order-bottom">
      <view class="total">
        <view class="t">
          <text class="label">商品合计：</text>
          <text class="txt">￥{{orderInfo.goodsPrice}}</text>
        </view>
        <view class="t">
          <text class="label">运费：</text>
          <text class="txt">￥{{orderInfo.freightPrice}}</text>
        </view>
        <view class="t">
          <text class="label">优惠减免：</text>
          <text class="txt">- ￥{{orderInfo.discountPrice}}</text>
        </view>
      </view>
      <view class="pay-fee">
        <text class="label">实付：</text>
        <text class="txt">￥{{orderInfo.actualPrice}}</text>
      </view>

    </view>
  </view>
  <view class="order-goods" v-if="isShared==1 && !orderInfo.handleOption.giftRecive">
    <view class="h">
      <view class="label">提示{{createUserName?': '+createUserName+'【发起】':''}}{{receiveUserName?'---------->'+receiveUserName+'【收取】':''}}</view>
    </view>
    <view class="fetch-msg">礼物已被收取或发起者已提货</view>
  </view>

  <view class="order-goods" v-else>
    <view class="h">
      <view class="label">取货码</view>
    </view>
    <view class="fetch-code">{{isShared==1 ? "******" : orderInfo.fetchCode}} </view>
  </view>

  <button class="giftBnt" v-if="isShared==1 && orderInfo.handleOption.giftRecive" @tap="giftOrderReceive">收取礼物</button>
  <button class="giftBnt" v-if="isShared==0 && orderInfo.handleOption.giftSend" open-type="share">赠送给好友</button>
</view>
</template>

<script>
const util = require("../../../utils/util.js");
const api = require("../../../config/api.js");

export default {
  data() {
    return {
      orderId: 0,
      orderInfo: {},
      orderGoods: [],
      flag: false,
      isShared: 0,
      brand: {},
      handleOption: {},
      createUserName: null,
      receiveUserName: null
    };
  },

  components: {},
  props: {},
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数
    this.setData({
      orderId: options.id,
      isShared: options.isShared ? options.isShared : 0
    });
    this.getOrderDetail();
  },
  onReady: function () {// 页面渲染完成
  },
  onShow: function () {
    // 页面显示
    this.getOrderDetail();
  },
  onHide: function () {// 页面隐藏
  },
  onUnload: function () {// 页面关闭
  },
  // 页面分享
  onShareAppMessage: function () {
    let that = this;
    let userInfo = uni.getStorageSync('userInfo');
    let shareUserId = 1;

    if (userInfo) {
      shareUserId = userInfo.userId;
    }

    let orderId = that.orderId;
    util.request(api.GiftOrderSend, {
      orderId: orderId
    }).then(function (res) {
      if (res.errno === 0) {
        console.log(res.errno);
      }
    });
    let scene = "fetchOrder," + orderId + ",user," + shareUserId;
    console.log('分享地址：' + '/pages/index/index?scene=' + scene);
    return {
      title: userInfo.nickName + ' 送你一个礼物',
      desc: '赠送订单，赶快手下吧！',
      path: '/pages/index/index?scene=' + scene
    };
  },
  methods: {
    getOrderDetail: function () {
      uni.showLoading({
        title: '加载中'
      });
      setTimeout(function () {
        uni.hideLoading();
      }, 2000);
      let that = this;
      let detailUrl = that.isShared == 1 ? api.GiftOrderDetail : api.OrderDetail;
      util.request(detailUrl, {
        orderId: that.orderId
      }).then(function (res) {
        if (res.errno === 0) {
          console.log(res.data);
          that.setData({
            orderInfo: res.data.orderInfo,
            orderGoods: res.data.orderGoods,
            brand: res.data.brand,
            createUserName: res.data.createUserName,
            receiveUserName: res.data.receiveUserName,
            handleOption: res.data.orderInfo.handleOption
          });
        }

        uni.hideLoading();
      });
    },
    showLocation: function (e) {
      let that = this;
      uni.openLocation({
        latitude: that.brand.latitude,
        longitude: that.brand.longitude,
        name: that.brand.name,
        address: that.brand.address
      });
    },
    giftOrderReceive: function () {
      let that = this;
      let orderId = that.orderId;
      util.request(api.GiftOrderReceive, {
        orderId: orderId
      }).then(function (res) {
        if (res.errno === 0) {
          try {
            uni.setStorageSync('tab', 2); //切换到待发货订单
          } catch (e) {}

          uni.navigateTo({
            url: '/pages/ucenter/order/order'
          });
        } else {
          util.showErrorToast(res.errmsg);
        }
      });
    }
  }
};
</script>
<style>
page {
  height: 100%;
  width: 100%;
  background: #f4f4f4;
}

.order-info {
  padding-top: 25rpx;
  background: #fff;
  height: auto;
  padding-left: 31.25rpx;
  overflow: hidden;
}

.item-a {
  padding-left: 31.25rpx;
  height: 42.5rpx;
  padding-bottom: 12.5rpx;
  line-height: 30rpx;
  font-size: 30rpx;
  color: #666;
}

.item-b {
  padding-left: 31.25rpx;
  height: 29rpx;
  line-height: 29rpx;
  margin-top: 12.5rpx;
  margin-bottom: 41.5rpx;
  font-size: 30rpx;
  color: #666;
}

.item-c {
  margin-left: 31.25rpx;
  border-top: 1px solid #f4f4f4;
  height: 103rpx;
  line-height: 103rpx;
}

.item-c .l {
  float: left;
}

.item-c .r {
  height: 103rpx;
  float: right;
  display: flex;
  align-items: center;
  padding-right: 16rpx;
}

.item-c .r .btn {
  float: right;
}

.item-c .cost {
  color: #b4282d;
}

.item-c .btn {
  line-height: 66rpx;
  border-radius: 5rpx;
  text-align: center;
  margin: 0 15rpx;
  padding: 0 20rpx;
  height: 66rpx;
}

.item-c .btn.active {
  background: #b4282d;
  color: #fff;
}

.order-goods {
  margin-top: 20rpx;
  background: #fff;
}

.order-goods .h {
  height: 93.75rpx;
  line-height: 93.75rpx;
  margin-left: 31.25rpx;
  border-bottom: 1px solid #f4f4f4;
  padding-right: 31.25rpx;
}

.order-goods .h .label {
  float: left;
  font-size: 30rpx;
  color: #333;
}

.order-goods .h .status {
  float: right;
  font-size: 30rpx;
  color: #b4282d;
}

.order-goods .item {
  display: flex;
  align-items: top;
  height: 202rpx;
  margin-left: 31.25rpx;
  margin-bottom: 15.25rpx;
  padding-right: 31.25rpx;
  border-bottom: 1px solid #f4f4f4;
}

.order-goods .item:last-child {
  border-bottom: none;
}

.order-goods .item .img {
  height: 145.83rpx;
  margin-top: 15.5rpx;
  width: 145.83rpx;
  background: #f4f4f4;
}

.order-goods .item .img image {
  height: 145.83rpx;
  width: 145.83rpx;
}

.order-goods .item .info {
  flex: 1;
  height: 145.83rpx;
  margin-left: 20rpx;
}

.order-goods .item .t {
  margin-top: 14rpx;
  height: 45rpx;
  line-height: 45rpx;
  margin-bottom: 8.5rpx;
}

.order-goods .item .t .name {
  display: block;
  float: left;
  height: 33rpx;
  line-height: 33rpx;
  color: #333;
  font-size: 30rpx;
}

.order-goods .item .t .number {
  display: block;
  float: right;
  height: 29rpx;
  text-align: right;
  line-height: 29rpx;
  color: #333;
  font-size: 30rpx;
}

.order-goods .item .attr {
  height: 29rpx;
  line-height: 29rpx;
  color: #666;
  margin-bottom: 25rpx;
  font-size: 25rpx;
}

.order-goods .item .price {
  display: block;
  float: left;
  height: 30rpx;
  line-height: 30rpx;
  color: #333;
  font-size: 30rpx;
}

.order-goods .item .btn {
  height: 50rpx;
  line-height: 50rpx;
  border-radius: 40rpx;
  text-align: center;
  display: block;
  float: right;
  margin: 0 15rpx;
  padding: 0 20rpx;
}

.order-goods .item .btn.active {
  background: #ee9e09;
  color: #fff;
  border-radius: 40rpx;
}

.order-bottom {
  margin-top: 20rpx;
  padding-left: 31.25rpx;
  height: auto;
  overflow: hidden;
  background: #fff;
}

.order-info .address {
  height: 128rpx;
  padding-top: 25rpx;
}

.order-info .t {
  height: 60rpx;
  line-height: 55rpx;
  margin-bottom: 7.5rpx;
}

.order-info .lable {
  display: inline-block;
  height: 35rpx;
  width: 220rpx;
  line-height: 35rpx;
  font-size: 30rpx;
}

.order-info .value {
  display: inline-block;
  height: 35rpx;
  line-height: 35rpx;
  font-size: 30rpx;
  color: #999;
}

.order-info .b {
  height: 50rpx;
  line-height: 40rpx;
  font-size: 30rpx;
  color: #999;
  padding-right: 10rpx;
  margin-bottom: 40rpx;
}

.order-bottom .total {
  height: 136rpx;
  padding-top: 20rpx;
  border-bottom: 1px solid #f4f4f4;
}

.order-bottom .total .t {
  height: 30rpx;
  line-height: 30rpx;
  margin-bottom: 7.5rpx;
}

.order-bottom .total .label {
  width: 250rpx;
  height: 35rpx;
  color: #999;
  line-height: 35rpx;
  font-size: 30rpx;
  float: left;
}

.order-bottom .total .txt {
  height: 35rpx;
  float: right;
  padding-right: 31.25rpx;
  line-height: 35rpx;
  font-size: 30rpx;
}

.order-bottom .pay-fee {
  height: 81rpx;
  line-height: 81rpx;
}

.order-bottom .pay-fee .label {
  width: 250rpx;
  color: #333;
  font-weight: bold;
  float: left;
}

.order-bottom .pay-fee .txt {
  float: right;
  padding-right: 31.25rpx;
  color: #b4282d;
}

.order-express {
  margin-top: 20rpx;
  width: 100%;
  height: 100rpx;
  background: #fff;
}

.order-express .title {
  float: left;
  margin-bottom: 20rpx;
  padding: 20rpx;
}

.order-express .ti {
  float: right;
  width: 52rpx;
  height: 52rpx;
  margin-right: 16rpx;
  margin-top: 28rpx;
}

.order-express .t {
  font-size: 29rpx;
  margin-left: 10.25rpx;
  color: #a78845;
}

.order-express .b {
  font-size: 29rpx;
  margin-left: 10.25rpx;
  color: #a78845;
}

.order-express .traces {
  padding: 17.5rpx;
  background: #fff;
  border-bottom: 1rpx solid #f1e6cdcc;
}

.order-express .trace {
  padding-bottom: 17.5rpx;
  padding-top: 17.5rpx;
  background: #fff;
}

.order-express .acceptTime {
  margin-top: 20rpx;
  margin-right: 40rpx;
  text-align: right;
  font-size: 26rpx;
}

.order-express .acceptStation {
  font-size: 26rpx;
}

.about-item{
  background: white;
  border-top: solid #f2f2f2 0.2rpx;
  border-bottom: solid #f2f2f2 0.2rpx;
  width: 100%;
  height: 100rpx;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.about-item .item-left{
  font-size: 30rpx;
  margin-left: 15rpx;
  margin-top: auto;
  margin-bottom: auto;
}
.about-item .item-right{
  margin-right: 15rpx;
  margin-top: auto;
  margin-bottom: auto;
}
.about-item .right-icon{
  width: 40rpx;
  height: 40rpx;
}
.fetch-code{
  width: 100%;
  height: 100rpx;
  flex-direction: row;
  text-align: center;
  vertical-align: middle;
  font-size: 50rpx;
  line-height: 100rpx;
  color: #f00;
  font-weight: bold;
}
.fetch-msg{
  width: 100%;
  height: 100rpx;
  flex-direction: row;
  text-align: center;
  vertical-align: middle;
  font-size: 30rpx;
  line-height: 100rpx;
  color: #f00;
  font-weight: bold;
}

.giftBnt{background-color:#FF654B;font-size:32rpx;color:#fff;width:690rpx;height:90rpx;border-radius:50rpx;text-align:center;line-height:90rpx;margin:76rpx auto 0 auto;}
</style>